/*
 * Copyright (C) 2016 Facishare Technology Co., Ltd. All Rights Reserved.
 */
package com.wlh.animation.demo;

import com.wlh.animation.R;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

/**
 * 矩形 渐变成圆形的动画
 * @author weilh
 *         <b>DATE</b> 2016/7/14.
 */
public class RectToCircleAct extends AppCompatActivity{

    private RectToCircleView rectToCircleView;
    private View loadingBtn, loadingSuccessBtn;
    private TextView textView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rect_to_circle);
        loadingBtn = findViewById(R.id.loading);
        loadingSuccessBtn = findViewById(R.id.loading_success);
        textView = (TextView) findViewById(R.id.text);
        loadingSuccessBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                rectToCircleView.startRevertAnimation();
                rectToCircleView.endLoadingAnimation();
                rectToCircleView.startAnimation();
                textView.setVisibility(View.GONE);
                textView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ObjectAnimator animator = ObjectAnimator.ofInt(textView, "alpha", 0, 1);
                        ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(textView, "textSize", 10, 16, 15);
                        AnimatorSet animatorSet = new AnimatorSet();
                        animatorSet.setDuration(400);
//                        animatorSet.setInterpolator(new AccelerateInterpolator());
                        animatorSet.playTogether(animator, scaleXAnimator);
                        textView.setVisibility(View.VISIBLE);
                        animatorSet.start();
                    }
                }, 2000);
            }
        });
        rectToCircleView = (RectToCircleView) findViewById(R.id.rect_to_circle_view);
        loadingBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                rectToCircleView.startAnimation();
                 rectToCircleView.startLoadingAnimation();
                textView.setVisibility(View.GONE);
//                ObjectAnimator colorAnimator = ObjectAnimator.ofInt(view, "backgroundColor", Color.YELLOW, Color
//                        .GREEN);
//                colorAnimator.setEvaluator(ArgbEvaluator.getInstance());
//                colorAnimator.setDuration(3000);
//
//                ObjectAnimator scaleAnimator = ObjectAnimator.ofFloat(view, "scaleX",1f, 0.5f, 1f);
//                scaleAnimator.setDuration(2000);
//
//                AnimatorSet animatorSet = new AnimatorSet();
//
//                animatorSet.playTogether(colorAnimator, scaleAnimator);
//                animatorSet.start();
            }
        });

    }
}
